<?php
/**
 * @author Paolo Bertuzzo
 * 
 */
namespace User;

use User\Controller\AuthenticationController;
use User\Service\CustomerService;
use User\Helper\AuthenticationAnchorHelper;
use User\Controller\CheckoutController;
use Utilities\Geolocation\GeolocationService;
use Catalog\Service\StoreService;
use Catalog\Data\StoreDao;
use Catalog\Data\BasketDao;
use Catalog\Data\BasketItemDao;
use User\Data\OrderHeaderDao;
use User\Data\OrderItemDao;
use Catalog\Data\LocalizedProductTextDao;
use Catalog\Data\ProductPriceDao;
use Catalog\Data\ProductImageDao;
use Catalog\Data\AttributeValuePriceDao;
use Catalog\Data\AttributeDao;
use Catalog\Service\BasketService;
use User\Helper\AddressFormHelper;
use User\Service\CountryService;
use User\Service\OrderService;
use User\Data\OrderAddressDao;
use User\Data\CustomerAddressDao;
use User\Helper\CustomerFormHelper;

return array(
    
    // Module controllers
    'controllers' => array(
        // Factories for controllers. This solves dependencies injection
        'factories' => array(
            'authentication' => function ($serviceManager)
            {
                $logger = $serviceManager->getServiceLocator()->get('Zend\Log');
                $entityManager = $serviceManager->getServiceLocator()->get('doctrine.entitymanager.orm_default');
                
                return new AuthenticationController(new CustomerService(new Data\CustomerDao($entityManager, $logger),
                    new Data\CustomerAddressDao($entityManager, $logger), $logger), $logger);
            },
            
            'checkout' => function ($serviceManager)
            {
                $logger = $serviceManager->getServiceLocator()->get('Zend\Log');
                $entityManager = $serviceManager->getServiceLocator()->get('doctrine.entitymanager.orm_default');
                
                return new CheckoutController(new BasketService(new BasketDao($entityManager, $logger),
                    new BasketItemDao($entityManager, $logger),
                    new LocalizedProductTextDao($entityManager, $logger),
                    new ProductPriceDao($entityManager, $logger),
                    new ProductImageDao($entityManager, $logger),
            	    new AttributeValuePriceDao($entityManager, $logger),
                    new AttributeDao($entityManager, $logger)),
                    new CustomerService(new Data\CustomerDao($entityManager, $logger),
                    new Data\CustomerAddressDao($entityManager, $logger), $logger), 
                    new CountryService(new Data\CountryDao($entityManager, $logger), 
                    new Data\StateDao($entityManager, $logger)),
                    new OrderService(new BasketDao($entityManager, $logger),
                    new BasketItemDao($entityManager, $logger), 
                    new OrderHeaderDao($entityManager, $logger),
                    new OrderItemDao($entityManager, $logger),
                    new OrderAddressDao($entityManager, $logger),
                    new CustomerAddressDao($entityManager, $logger)));
            }
        )
    ),
    
    // View helpers
    'view_helpers' => array(
        'factories' => array(
            'authentication_anchor' => function ($helperPluginManager)
            {
                return new AuthenticationAnchorHelper();
            },
            
            'address_form' => function ($helperPluginManager)
            {
                return new AddressFormHelper();
            },
            
            'customer_form' => function ($helperPluginManager)
            {
            	return new CustomerFormHelper();
            }
        )
    ),
    
    // Module views
    'view_manager' => array(
        'template_map' => array(
            'user/checkout/summary' => __DIR__ . '/../view/user/checkout/summary.phtml',
            'user/checkout/check-addresses' => __DIR__ . '/../view/user/checkout/check_addresses.phtml',
            'user/checkout/check-customer' => __DIR__ . '/../view/user/checkout/check_customer.phtml',
            'user/checkout/prepare-payment' => __DIR__ . '/../view/user/checkout/prepare_payment.phtml',
            'user/authentication/error' => __DIR__ . '/../view/user/authentication/error.phtml',
            'user/authentication/authenticate-from-facebook-callback' => __DIR__ . '/../view/user/authentication/authenticate-from-facebook-callback.phtml',
            'helper/authentication_anchor' => __DIR__ . '/../view/user/helper/authentication_anchor.phtml',
            'helper/address_form' => __DIR__ . '/../view/user/helper/address_form.phtml',
            'helper/customer_form' => __DIR__ . '/../view/user/helper/customer_form.phtml'
        )
    ),
    
    'translator' => array(
        'translation_file_patterns' => array(
            array(
                'type' => 'gettext',
                'base_dir' => __DIR__ . '/../language',
                'pattern' => '%s.mo',
                'text_domain' => 'user'
            )
        )
    )
)
;